package com.isoft.systemprovidor.service.perinfor;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.isoft.systemprovidor.bean.ResponseData;
import com.isoft.systemprovidor.bean.ResultCode;
import com.isoft.systemprovidor.dao.perinfor.Perinfor_Relative_Relocation_Dao;
import com.isoft.systemprovidor.entity.perinfor.Perinfor_Relative_Relocation;
import com.isoft.systemprovidor.util.IdUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

@Service
@Slf4j
public class Perinfor_Relative_Relocation_Service {
    @Autowired
    Perinfor_Relative_Relocation_Dao relocation_dao;
    /*查看家庭成员的移居信息*/
    public ResponseData selectRelocation(String sysuserid){
        ResponseData responseData =new ResponseData();
        if (sysuserid.isEmpty()|| null == sysuserid){
            responseData.setErrorCode(ResultCode.PARAM_IS_BLANK.getCode());
            responseData.setMsg(ResultCode.PARAM_IS_BLANK.getMessage());
            return responseData;
        }
        QueryWrapper wrapper = new QueryWrapper<>();
        wrapper.eq("sysuserid",sysuserid);
        wrapper.eq("islock",0);
        responseData.setErrorCode(ResultCode.SUCCESS.getCode());
        responseData.setMsg(ResultCode.SUCCESS.getMessage());
        responseData.setData(relocation_dao.selectList(wrapper));
        return responseData;
    }
    /*修改家庭成员的移居信息*/
    public boolean changeRelocation(Perinfor_Relative_Relocation relocation){
        if((null == relocation)||(!IdUtil.idCheck(relocation.getId()))||(relocation.getSysuserid().isEmpty())){
            return false;
        }
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("sysuserid",relocation.getSysuserid());
        wrapper.eq("id",relocation.getId());
        return relocation_dao.update(relocation,wrapper)>0;

    }
    /*插入家庭成员的移居信息*/
    public boolean insertRelocation(Perinfor_Relative_Relocation relocation){
        if((null == relocation)||(relocation.getSysuserid().isEmpty())){
            return false;
        }
        return relocation_dao.insert(relocation)>0;
    }
    /*删除家庭成员的移居信息*/
    public boolean islockRelocation(Integer id ,String sysuserid){
        if (id==null|| sysuserid.isEmpty()){
            return false;
        }
        Perinfor_Relative_Relocation relocation = new Perinfor_Relative_Relocation();
        relocation.setIslock(1);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.eq("id",id);
        wrapper.eq("sysuserid",sysuserid);
        return relocation_dao.update(relocation,wrapper)>0;
    }
}
